package com.ovopark.firecar.activity

import android.app.Activity
import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.view.View
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import cn.yhq.dialog.core.DialogBuilder
import cn.yhq.dialog.core.IDialog
import com.ovopark.firecar.manager.DataManager
import com.ovopark.firecar.okhttp.RsGenerator
import com.ovopark.firecar.okhttp.TokenInterceptor
import com.ovopark.firecar.view.BaseView

open class BaseActivity : AppCompatActivity() , BaseView {
    lateinit var loadingDialog : IDialog

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(null)
        RsGenerator.createNewRetrofit(DataManager.getInstance().getBaseUrl(), TokenInterceptor())
        loadingDialog = DialogBuilder.loadingDialog0(this).create()

        initView()
    }

    override fun initView() {


    }

    override fun onResume() {
        super.onResume()
        // 全屏展示
        // 全屏展示
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                // 全屏显示，隐藏状态栏和导航栏，拉出状态栏和导航栏显示一会儿后消失。
                this.getWindow().getDecorView().setSystemUiVisibility(
                    View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                            or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                            or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                            or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                            or View.SYSTEM_UI_FLAG_FULLSCREEN
                            or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
                )
            } else {
                // 全屏显示，隐藏状态栏
                this.getWindow().getDecorView()
                    .setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN)
            }
        }
    }

    fun readyGo(mActivity: Activity, clazz: Class<*>){
        val intent : Intent = Intent(mActivity,clazz)
        startActivity(intent)
    }

    fun readyGo(mActivity: Activity, clazz: Class<*>, bundle : Bundle){
        val intent : Intent = Intent(mActivity,clazz)
        intent.putExtras(bundle)
        startActivity(intent)
    }


    fun readyGoForResult(mActivity: Activity, clazz: Class<*>, requestCode : Int){
        val intent : Intent = Intent(mActivity,clazz)
        startActivityForResult(intent,requestCode)
    }

    fun toast(msg : String){
        Toast.makeText(this,"${msg}",Toast.LENGTH_SHORT).show()
    }


}